package behavior.command.command;

import behavior.command.receiver.BackReceiver;
import behavior.command.receiver.ForwardReceiver;
import behavior.command.MoveObject;
import behavior.command.receiver.MoveReceiver;

/**
 * 移动命令
 */
public class MoveCommand implements IMoveCommand {

    private MoveReceiver moveReceiver;


    private MoveObject moveObject;



    public MoveCommand(MoveReceiver moveReceiver) {
        this.moveReceiver = moveReceiver;
        this.moveObject = moveReceiver.getMoveObject();
    }


    @Override
    public void execute() {
        moveReceiver.action();
    }

    @Override
    public void undo() {

        if (moveReceiver instanceof ForwardReceiver) {
           new BackReceiver(moveObject).action();
        } else if (moveReceiver instanceof BackReceiver) {
            new ForwardReceiver(moveObject).action();
        }

    }

}
